package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import com.wanmait.movie.entity.Brand;
import com.wanmait.movie.entity.VO.BrandVO;
import com.wanmait.movie.mapper.BrandMapper;
import com.wanmait.movie.service.BrandService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName: BrandServiceImpl
 * Package: com.wanmait.movie.service.impl
 * Description:
 *
 * @Author Fengxd
 * @Create 2023/12/16 11:48
 * @Version 1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {
    @Resource
    private BrandMapper brandMapper;
    @Override
    public List<BrandVO> getBrandInfo() {
        return this.list().stream().map(brand -> new BrandVO(brand.getId(), brand.getBrandName())).collect(Collectors.toList());
    }
    @Override
    public PageInfo<Brand> getBrandList(int pageNum, int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        LambdaQueryWrapper<Brand> queryWrapper = new LambdaQueryWrapper<>();
        List<Brand> brands = brandMapper.selectList(queryWrapper);
        return new PageInfo<>(brands);
    }

}
